package com.ojoin.trade.t0loan_core.web.dao.impl;

import java.util.HashMap;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.ojoin.trade.common.exception.BusinessException;
import com.ojoin.trade.common.exception.DaoException;
import com.ojoin.trade.common.web.dao.impl.BaseDaoImpl;
import com.ojoin.trade.t0loan_core.web.dao.TbT0RefundTaskDao;
import com.ojoin.trade.t0loan_core.web.domain.TbT0RefundTask;
import com.ojoin.trade.t0loan_core.web.domain.TbT0RefundTaskVO;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 15-10-26
 * Time: 上午11:24
 * To change this template use File | Settings | File Templates.
 */
@Repository
public class TbT0RefundTaskDaoImpl extends BaseDaoImpl<TbT0RefundTask> implements TbT0RefundTaskDao {

	@Override
	public List<TbT0RefundTaskVO> queryAllUserUnsuccessRefundTask()
			throws BusinessException {
		String mapMethodName = "queryAllUserUnsuccessRefundTask";
        try { 
            List list = this.sqlSessionTemplate.selectList(getSqlName(mapMethodName));
            if (list != null && list.size() >0)
              return list ;
        } catch (Exception e) {
            throw new DaoException(String.format("查询所有用户未操作成功的回款记录出错！语句：%s",
                    getSqlName(mapMethodName)), e);
        }
        return null;
	}

	@Override
	public TbT0RefundTaskVO queryUserLastRefundTaskById(int joinuserid)
			throws BusinessException {
		String mapMethodName = "queryUserLastRefundTaskById";
        try { 
            return this.sqlSessionTemplate.selectOne(getSqlName(mapMethodName), joinuserid);
        } catch (Exception e) {
            throw new DaoException(String.format("查询所有用户未操作成功的回款记录出错！语句：%s",
                    getSqlName(mapMethodName)), e);
        }
	}

	@Override
	public int updateRefundTaskStatusAndMemoById(int id, int status, String memo, String orderid)
			throws BusinessException {
		String mapMethodName = "updateRefundTaskStatusAndMemoById";
        try { 
        	HashMap<String, Object> paramMap = new HashMap<String, Object>();
        	paramMap.put("id", id);
        	paramMap.put("state", status);
        	paramMap.put("memo", memo);
        	paramMap.put("orderid", orderid);
        	
            return this.sqlSessionTemplate.update(getSqlName(mapMethodName), paramMap);
        } catch (Exception e) {
            throw new DaoException(String.format("查询所有用户未操作成功的回款记录出错！语句：%s",
                    getSqlName(mapMethodName)), e);
        }
	}
 
}
